package hello.configuration.restful;

import com.fasterxml.jackson.databind.ObjectMapper;
import hello.configuration.restful.validator.AfterDeleteValidator;
import hello.configuration.restful.validator.BeforeDeleteValidator;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
import org.springframework.data.rest.webmvc.BaseUri;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;

import java.util.List;

/**
 * @Description:
 * @Author: m01
 * @Date: created at  2018/12/19  16:09
 * @Modified By:
 */

@Configuration
public class SelfRepositoryRestMvcConfiguration extends  RepositoryRestConfigurerAdapter {

    @Override
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.setBasePath("/api");
        config.setDefaultPageSize(10);
    }

    public SelfRepositoryRestMvcConfiguration() {
        super();
    }

    @Override
    public void configureConversionService(ConfigurableConversionService conversionService) {

        super.configureConversionService(conversionService);
    }

    @Override
    public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
        validatingListener.addValidator("beforeDelete",new BeforeDeleteValidator());
        validatingListener.addValidator("afterDelete",new AfterDeleteValidator());
//        super.configureValidatingRepositoryEventListener(validatingListener);
    }

    @Override
    public void configureExceptionHandlerExceptionResolver(ExceptionHandlerExceptionResolver exceptionResolver) {
        super.configureExceptionHandlerExceptionResolver(exceptionResolver);
    }

    @Override
    public void configureHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
        super.configureHttpMessageConverters(messageConverters);
    }

    @Override
    public void configureJacksonObjectMapper(ObjectMapper objectMapper) {
        super.configureJacksonObjectMapper(objectMapper);
    }
}
